// @ts-ignore
import axios from "axios";
// @ts-ignore
import SystemConfig from "@/config/SystemConfig";

let axiosInstance = axios.create({
    baseURL: SystemConfig.BASE_URL,
    withCredentials: true,
    timeout: 10000
});
axiosInstance.interceptors.request.use((config: any) => {
    config.headers['Authorization'] = 'Bearer ' + sessionStorage.getItem('token')
    return config
})

axiosInstance.interceptors.response.use(
    (response:any) => {
        switch (response.data.code) {
            case 50000:
                ElMessage.error('系统错误,请联系网站管理员')
                break
            case 40001:
                ElMessage.warning('您的权限不足')
                break
        }
        return response
    },
    (error: any) => {
        return Promise.reject(error)
    }
)
export default axiosInstance
